package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * 完成用户注册功能
 * 要求用户在控制台输入条件
 * 然后将信息插入userinfo表中完成注册
 */
public class RegDemo {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"欢迎注册","注册");
        System.out.println(userInfo);
//        //1. 加载驱动程序
//        Class.forName("com.mysql.cj.jdbc.Driver");
//        //2.与数据库建立连接
//        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3308/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true","root","1234");
//        System.out.println("与数据库成功建立连接");
//        //3.创建语句执行对象
//        Statement statement = connection.createStatement();
//
//        Scanner scan = new Scanner(System.in);
//        System.out.println("请输入用户,密码,昵称,年龄");
//        String username = scan.nextLine();
//        String password = scan.nextLine();
//        String nickname = scan.nextLine();
//        String age = scan.nextLine();
//
//
//        String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
//                "VALUES("+username+"','"+password+"','"+nickname+"','"+age+")";
//        int num = statement.executeUpdate(sql);
//        if (num > 0){
//            System.out.println("插入成功");
//        }
//        connection.close();
    }
}
